package com.simon.gpsinfo;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import android.app.Activity;
import android.location.Location;
import android.location.LocationListener;
import android.widget.TextView;

public class GPSInfoDisplay {
	
	private Activity activity=new Activity();
	
	public GPSInfoDisplay(Activity activity)
	{
		activity=activity;
	}
	
	void makeUseOfNewLocation( Location location) {
		// DBGPSInfo dbgpsinfo = new DBGPSInfo(this);
		activity.Accuracy = (TextView) findViewById(R.id.Accuracy);
		Altitude = (TextView) findViewById(R.id.Altitude);
		Bearing = (TextView) findViewById(R.id.Bearing);
		Speed = (TextView) findViewById(R.id.Speed);
		Speed1 = (TextView) findViewById(R.id.Speed1);

		Latitude = (TextView) findViewById(R.id.Latitude);
		Longitude = (TextView) findViewById(R.id.Longitude);
		Provider = (TextView) findViewById(R.id.Provider);
		Time = (TextView) findViewById(R.id.Time);

		float accuracy = location.getAccuracy();
		double altitude = location.getAltitude();
		float bearing = location.getBearing();
		float speed = location.getSpeed();

		double latitude = location.getLatitude();
		double longitude = location.getLongitude();
		String provider = location.getProvider();

		DecimalFormat decimalFormat = new DecimalFormat("####.######");

		if (location.hasAccuracy()) {

			Accuracy.setText("" + decimalFormat.format(accuracy) + " [m]");

		} else {
			Accuracy.setText("brak danych");
		}

		if (location.hasAltitude()) {
			Altitude.setText("" + decimalFormat.format(altitude) + " [m]");
		} else {
			Altitude.setText("brak danych.");
		}

		if (location.hasBearing()) {
			Bearing.setText("" + decimalFormat.format(bearing));
		} else {
			Bearing.setText("Namiar off.");
		}
		if (location.hasSpeed()) {
			Speed.setText("" + decimalFormat.format(speed) + " [m/s]");
			Speed1.setText("" + decimalFormat.format((speed * 3.6)) + " [km/h]");
		} else {
			Speed.setText("brak danych.");
			Speed1.setText("brak danych.");
		}

		Latitude.setText("" + decimalFormat.format(latitude));
		Longitude.setText("" + decimalFormat.format(longitude));
		Provider.setText("" + provider);

		try {
			Calendar cal = Calendar.getInstance();
			cal.setTimeInMillis(location.getTime());
			String format = "dd/MM/yyyy HH:mm:ss";
			SimpleDateFormat sdf = new SimpleDateFormat(format);
			String dateString = sdf.format(cal.getTime());
			Time.setText("" + dateString);
		} catch (NullPointerException exp) {
			exp.getMessage();
		} catch (IllegalArgumentException exp) {
			exp.getMessage();
		}

		// dbgpsinfo.createRow(location.getTime(), speed, accuracy, altitude,
		// bearing, latitude, longitude, provider);

	}

}
